/*
 * @Author: szx
 * @Date: 2022-03-20 15:14:14
 * @LastEditTime: 2022-03-20 15:24:35
 * @Description:
 * @FilePath: \leetcode\6000-6100\6028\6028.js
 */
/**
 * @param {string} directions
 * @return {number}
 */
 var countCollisions = function (directions) {
    let l = 0,
        r = directions.length - 1;
    while (l <= r && directions[l] == 'L') ++l;
    while (l <= r && directions[r] == 'R') --r;
    let res = 0;
    for (let i = l; i <= r; ++i) if (directions[i] == 'L' || directions[i] == 'R') ++res;
    return res;
};
